﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TibcoQueueMonitor.TibcoAdminManagers;
using TibcoQueueMonitor.Entities;
using System.IO;

namespace TibcoQueueMonitor.UnitTests
{
    [TestClass]
    public class DataParserTests
    {
        [TestMethod]
        public void ConsumersParserTest()
        {
            StringBuilder data = new StringBuilder("Command: show consumers\r\n                                                                          Msgs Sent          \r\n    Id   Conn User     T Queue                                         SAS Sent Size   Uptime \r\n 54414  57782 BizEms   Q STN.BTS.NL.EndurToBizTalk.LPS.Perf            +C-    0    0 216:46:59 ");

            Parse(data);
        }

        [TestMethod]
        public void ConnectionsParserTest()
        {
            StringBuilder data = new StringBuilder("Command: show connections\r\nL  ID   FSXT  S  Host          User      ClientID Sess     Uptime\r\nJ  68   ---Q  +  amsdc1-s-3017 EndurEms              1   38:47:32");

            Parse(data);
        }

        [TestMethod]
        public void QueuesParserTest()
        {
            StringBuilder data = new StringBuilder("Command: show queues\r\n  Queue Name                                    SNFGXIBCT  Pre  Rcvrs     Msgs    Size   \r\n* STN.BTS.NL.BizTalkToEndur.EnergyExchange.*    ---------    5*     0        0     0.0 Kb ");

            Parse(data);
        }

        private void Parse(StringBuilder consoleOutputSample)
        {
            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream);

            writer.WriteLine(consoleOutputSample.ToString());
            writer.Flush();
            stream.Position = 0;
            StreamReader reader = new StreamReader(stream);
            try
            {
                TibcoAdminDataParser.ParseStream(reader);
            }
            catch
            {
            }
            finally
            {
                writer.Close();
                reader.Close();
            }
        }
    }
}
